﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace StatusPlan3
{
    /// <summary>
    /// Interaction logic for Window_LoadingSmall.xaml
    /// </summary>
    public partial class Window_LoadingSmall : Window
    {
        public Window_LoadingSmall()
        {
            showDelegate = new SetTitleDelegate(this.setTitle);
            startProgressBarDelegate = new StartProgressBarDelegate(this.startProgressBar);
            stopProgressBarDelegate = new StopProgressBarDelegate(this.stopProgressBar);
            myAddToLogDelegate = new MyAddToLogDelegate(this.myAddToLog);
            myShowDelegate = new MyShowDelegate(this.myShow);
            myColseDelegate = new MyColseDelegate(this.myColse);
            InitializeComponent();
        }

        public delegate void SetTitleDelegate(String title);
        SetTitleDelegate showDelegate;
        public void setTitle(String title)
        {
            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                TextBlock_Title.Text = title;
            }
            else
            {
                this.Dispatcher.Invoke(showDelegate, title);
            }
        }

        public delegate void StartProgressBarDelegate();
        StartProgressBarDelegate startProgressBarDelegate;

        public void startProgressBar()
        {
            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                radProgressBar1.IsIndeterminate = true;
            }
            else
            {
                this.Dispatcher.Invoke(startProgressBarDelegate);
            }   
        }

        public delegate void StopProgressBarDelegate();
        StopProgressBarDelegate stopProgressBarDelegate;
        public void stopProgressBar()
        {
            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                radProgressBar1.IsIndeterminate = false;
            }
            else
            {
                this.Dispatcher.Invoke(stopProgressBarDelegate);
            }
        }

        public delegate void MyAddToLogDelegate(String s);
        MyAddToLogDelegate myAddToLogDelegate;
        public void myAddToLog(String s)
        {

            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                TextBox_Log.Text = s + "\n" + TextBox_Log.Text;
            }
            else
            {
                this.Dispatcher.Invoke(myAddToLogDelegate, s);
            }

            
        }

        public delegate void MyShowDelegate();
        MyShowDelegate myShowDelegate;
        public void myShow()
        {
            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                this.Show();
            }
            else
            {
                this.Dispatcher.Invoke(myShowDelegate);
            }

            
        }

        public delegate void MyColseDelegate();
        MyColseDelegate myColseDelegate;
        public void myColse()
        {
            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                this.Close();
            }
            else
            {
                this.Dispatcher.Invoke(myColseDelegate);
            }
            
        }
    }
}
